package com.reggie.module.entity.dto.setmealDto;

import com.reggie.module.entity.po.Setmeal;
import com.reggie.module.entity.po.SetmealDish;
import lombok.Data;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;

import static com.reggie.common.Constant.LOGIN_SESSION;

@Data
public class SetmealDto extends Setmeal {

    private List<SetmealDish> setmealDishes;

    private String categoryName;


    public Setmeal addSetmeal(SetmealDto setmealDto, HttpServletRequest request) {
        Setmeal setmeal = new Setmeal();
        setmeal.setId(setmealDto.getId());
        setmeal.setCategoryId(setmealDto.getCategoryId());
        setmeal.setName(setmealDto.getName());
        setmeal.setPrice(setmealDto.getPrice());
        setmeal.setCode("");
        setmeal.setDescription(setmealDto.getDescription());
        setmeal.setImage(setmealDto.getImage());
        setmeal.setCreateTime(LocalDateTime.now());
        setmeal.setUpdateTime(LocalDateTime.now());
        Long empId = (Long) request.getSession().getAttribute(LOGIN_SESSION);
        setmeal.setCreateUser(empId);
        setmeal.setUpdateUser(empId);
        return setmeal;
    }
}
